#include <utils/JsonUtil.h>

const string JsonUtil::stringify(const Value &doc, shared_ptr<string> buf)
{
    StringBuffer sb;
    Writer<StringBuffer> writer(sb);
    doc.Accept(writer);

    (*buf).assign(sb.GetString(), sb.GetSize());

    return *buf;
}

void JsonUtil::parseFile(Document &v, const char *fileName)
{
    ifstream in(fileName);
    ostringstream out;
    out << in.rdbuf();

    v.Parse(out.str().c_str());
}

void JsonUtil::printError(const Document &v)
{
    DLOG(WARNING) << "Error(offset " << (unsigned)v.GetErrorOffset() << "): " << GetParseError_En(v.GetParseError());
}
